const { ccclass, property } = cc._decorator;

import r from "./PlayerDataSys"
import n from "./AbTestMgr"
import l from "./PeripheralSystemDataMgr"
import s from "./EventMgr"
import c from "./GameEventType"
import u from "./Handler"
import p from "./frameworkManager"
import d from "./SdkHelper"
import h from "./GameService"
import f from "./EngineUtil"
import g from "./PageMgr";

export var TravelEvent  = {
    NONE : 0,
    MOM_GIVE_MOENY : 1,
    SCRAP_CARD : 2,
    OBSTACLE_TIGER : 3,
    PICKPOCKET : 4,
    SKILL : 5,
    HOTAIRBALLON : 6
}

export var OutSideLevelGuide  = {
    SHOW_THEME : 1,
    CITY_GUIDE : 2,
    CITY_REWARD : 3,
    FUND_GUIDE : 4,
    FUND_PROVICE : 5,
    CLICK_WITHDRAW : 6,
    FUND_WITHDRAW : 7,
    BREAKTHROUGH : 8,
    MOVE_REWARD : 9,
    CONTINUE_GAME : 10,
    CASH_WITHDRAW : 11,
    CLOCK_DAY : 12,
    CLOCK_GUIDE_DONE : 13
}

export var VideoBuriedPoint  = {
    DOUBLE_RED_PAPER : "double_red_paper",
    HOT_AIR_BALLON : "hot_air_ballon",
    ADD_STEP : "add_step",
    OBTAIN_HAMMER : "obtain_hammer",
    OBTAIN_BOW_AND_ARROW : "obtain_bow_and_arrow",
    OBTAIN_ARTILLERY : "obtain_artillery",
    MOM_GIVE_MOENY : "mom_give_money",
    SCRAP_CARD_1 : "scrap_card_1",
    SCRAP_CARD_2 : "scrap_card_2",
    OBSTACLE_TIGER : "obstacle_tiger",
    PICKPOCKET : "pickpocket",
    GIVE_SKILL : "give_skill",
    FORCE_ENCOURAGE : "force_encourage",
    INSERT_AD : "insert_ad",
    FULL_AD : "full_ad",
    SPLASH_AD : "splash_ad",
    FLY_BOX : "matchgame_fly_box"
}

@ccclass
class PeripheralSystemMgr {

    static TravelEvent  = {
        NONE : 0,
        MOM_GIVE_MOENY : 1,
        SCRAP_CARD : 2,
        OBSTACLE_TIGER : 3,
        PICKPOCKET : 4,
        SKILL : 5,
        HOTAIRBALLON : 6
    }
    
    static OutSideLevelGuide  = {
        SHOW_THEME : 1,
        CITY_GUIDE : 2,
        CITY_REWARD : 3,
        FUND_GUIDE : 4,
        FUND_PROVICE : 5,
        CLICK_WITHDRAW : 6,
        FUND_WITHDRAW : 7,
        BREAKTHROUGH : 8,
        MOVE_REWARD : 9,
        CONTINUE_GAME : 10,
        CASH_WITHDRAW : 11,
        CLOCK_DAY : 12,
        CLOCK_GUIDE_DONE : 13
    }
    
    static VideoBuriedPoint  = {
        DOUBLE_RED_PAPER : "double_red_paper",
        HOT_AIR_BALLON : "hot_air_ballon",
        ADD_STEP : "add_step",
        OBTAIN_HAMMER : "obtain_hammer",
        OBTAIN_BOW_AND_ARROW : "obtain_bow_and_arrow",
        OBTAIN_ARTILLERY : "obtain_artillery",
        MOM_GIVE_MOENY : "mom_give_money",
        SCRAP_CARD_1 : "scrap_card_1",
        SCRAP_CARD_2 : "scrap_card_2",
        OBSTACLE_TIGER : "obstacle_tiger",
        PICKPOCKET : "pickpocket",
        GIVE_SKILL : "give_skill",
        FORCE_ENCOURAGE : "force_encourage",
        INSERT_AD : "insert_ad",
        FULL_AD : "full_ad",
        SPLASH_AD : "splash_ad",
        FLY_BOX : "matchgame_fly_box"
    }

    static _instance;
    static _getInstance():PeripheralSystemMgr {
        PeripheralSystemMgr._instance || (PeripheralSystemMgr._instance = new PeripheralSystemMgr());
        return PeripheralSystemMgr._instance;
    };
    public getClockTaskList(e?, t?, a?) {
        void 0 === e && (e = false);
        void 0 === t && (t = false);
        p.log("获取每日打卡数据===res ==0000");
        h.getClockTaskList(u.create(this, function (o) {
            if (o && 1 == o.code) {
                Object.assign(o.data, {
                    guideEnter: e
                });
                Object.assign(o.data, {
                    guideEcperiment: t
                });
                var i = o.data.yes_clock_data;
                if ("{}" == JSON.stringify(i)) g.showPage("ClickEveryDayPage", o.data); else {
                    l.setYesClockData(i);
                    g.showPage("NotclaimedRewardPage");
                }
                a && a();
            } else o.message && f.showManageViewToast(o.message);
        }), u.create(this, function () {
            f.showManageViewToast("网络异常,请检查网络");
        }));
    };
    public getClockTaskReward(e, t, a) {
        void 0 === t && (t = 0);
        h.getClockTaskReward({
            task_id: e,
            ysd: t
        }, u.create(this,  (e) => {
            p.log("领取每日打卡奖励===res", e);
            if (e && 1 == e.code) {
                var o = e.data.clock_info, i = e.data.clock_in_days;
                if (o && o.progress) {
                    l.setClockData(o.progress);
                    l.setClockDays(i);
                    s.trigger(c.GAME_TOP_CLOCK_SHOW);
                    s.trigger(c.DAY_AND_FUD_SHOW);
                    s.trigger(c.CLICKDAY_PRO);
                }
                a && a(o);
                0 == t && d.reportData("clock_success");
            } else e.message && f.showManageViewToast(e.message);
        }), u.create(this, function () {
            f.showManageViewToast("网络异常,请检查网络");
        }));
    };
    public getExtractInfo(e?, t?, a?, o?) {
        void 0 === e && (e = false);
        void 0 === t && (t = false);
        void 0 === a && (a = false);
        h.getExtractInfo(u.create(this, function (i) {
            p.log("获取提现页面信息", i);
            if (i && 1 == o.code) {
                var r = o.data, n = r.cash_balance, s = r.extract_info, c = r.extract_count;
                l.setExtractInfo(s);
                l.setExtractCount(c);
                g.showPage("CashWithDrawPage", {
                    cash_balance: n,
                    isIncreasePageEnter: e,
                    extract_count: c,
                    isGuideEnter: t,
                    isGuideExperimentEnter: a,
                    fake_balance: o.data.fake_balance || 0
                });
                o && o();
            } else o.message && f.showManageViewToast(o.message);
        }), u.create(this, function () {
            f.showManageViewToast("网络异常,请检查网络");
        }));
    };
    public getExtractCashRecord(e) {
        h.getExtractCashRecord(u.create(this, function (t) {
            p.log("获取提现记录数据", t);
            if (t && 1 == t.code) {
                var a = t.data, o = a.total_cash, i = a.extract_record;
                g.showPage("CashWithDrawRecordPage", {
                    total_cash: o,
                    extract_record: i
                });
                e && e();
            } else t.message && f.showManageViewToast(t.message);
        }), u.create(this, function () {
            f.showManageViewToast("网络异常,请检查网络");
        }));
    };
    public getTravelExtractInfo(e?) {
        h.getTravelExtractInfo(u.create(this, function (t) {
            p.log("旅行基金提现页信息", t);
            if (t && 1 == t.code) {
                var a = t.data, o = a.gold_balance, i = a.extract_info, r = a.city_info;
                if (n.isOptimizeTravelFundFlag()) g.showPage("FundWithDrawExperimentPage", {
                    gold_balance: o,
                    extract_info: i,
                    city_info: r
                }); else {
                    var s = l.isHitVivoReviewBan(), c = l.isHitVivoNewUser();
                    p.log("命中vivo审核人员=====", s);
                    p.log("命中vivo自然渠道新增人员=====", c);
                    s || c ? g.showPage("FundWithDrawBanPage", {
                        gold_balance: o,
                        extract_info: i,
                        city_info: r
                    }) : g.showPage("FundWithDrawPage", {
                        gold_balance: o,
                        extract_info: i,
                        city_info: r
                    });
                }
                e && e();
            } else t.message && f.showManageViewToast(t.message);
        }), u.create(this, function () {
            f.showManageViewToast("网络异常,请检查网络");
        }));
    };
    public extractCash(e, t?) {
        h.extractCash({
            tx_id: e
        }, u.create(this,  (e) => {
            p.log("提现成功数据", e);
            if (e && 1 == e.code) {
                var a = e.data, o = a.cash_balance, i = a.extract_count;
                l.setExtractCount(i);
                r.cash_balance = o;
                s.trigger(c.UPDATE_USER_CASH);
                s.trigger(c.UPDATE_CASH_WITHDRAW);
                s.trigger(c.GAME_START_TOP_CASH);
                t && t();
            } else {
                -2035 == e.code ? f.showManageViewToast("每日30次提现机会已使用完，请明天再来吧") : f.showManageViewToast(e.message);
                s.trigger(c.UPDATE_CASH_WITHDRAW);
            }
        }), u.create(this, function () {
            f.showManageViewToast("网络异常,请检查网络");
        }));
    };
    public videoGetGold(e) {
        h.videoGetGold(u.create(this, function (t) {
            p.log("看视频获取金币", t);
            if (t && 1 == t.code) {
                var a = t.data;
                a.reward, a.video_count;
                e && e();
            } else t.message && f.showManageViewToast(t.message);
        }), u.create(this, function () {
            f.showManageViewToast("网络异常,请检查网络");
        }));
    };
    public getScollMsg(e?) {
        h.getScollMsg(u.create(this, function (t) {
            p.log("获取滚动公告数据", t);
            if (t && 1 == t.code) {
                var a = t.data.msg_list;
                l.setSrollMsgList(a);
                s.trigger(c.UPDATE_SCOLL_MSG);
                e && e();
            } else t.message && f.showManageViewToast(t.message);
        }), u.create(this, function () {
            f.showManageViewToast("网络异常,请检查网络");
        }));
    };
    public getTravelInfo(e) {
        h.getTravelInfo(u.create(this, function (t) {
            p.log("获取旅行数据", t);
            if (t && 1 == t.code) {
                s.trigger(c.PANADA_MOVE, {
                    data_info: t.data
                });
                e && e();
            } else t.message && f.showManageViewToast(t.message);
        }), u.create(this, function () {
            f.showManageViewToast("网络异常,请检查网络");
        }));
    };
    public getVideoReward(e, t = 0, a?) {
        void 0 === t && (t = 1);
        var n = {
            video_type: e,
            is_video: t
        };
        p.log("getUserCpm", r.getUserCpm());
        r.getUserCpm() && Object.assign(n, r.getUserCpm());
        p.log("getVideoReward====cpm", r.getUserCpm());
        h.getVideoReward(n, u.create(this, function (n) {
            p.log("获取看视频奖励===res", n);
            if (n && 1 == n.code) {
                var u = n.data, d = n.data, h = d.cash_balance, y = d.ggk, m = d.reward, _ = d.red_flag;
                Object.assign(u, {
                    video_type: e
                });
                a && a();
                if (e == TravelEvent.MOM_GIVE_MOENY) {
                    l.reportVideoBuriedPoint(TravelEvent.MOM_GIVE_MOENY);
                    g.showPage("TravelEventRewardPage", u);
                } else if (e == TravelEvent.OBSTACLE_TIGER || e == TravelEvent.PICKPOCKET) if (1 == t) {
                    g.showPage("TravelEventRewardPage", u);
                    e == TravelEvent.OBSTACLE_TIGER ? l.reportVideoBuriedPoint(TravelEvent.OBSTACLE_TIGER) : e == TravelEvent.PICKPOCKET && l.reportVideoBuriedPoint(TravelEvent.PICKPOCKET);
                } else {
                    g.showPage("DeductionToastPage");
                    r.cash_balance = h;
                    s.trigger(c.UPDATE_USER_CASH);
                } else if (e == TravelEvent.SCRAP_CARD) {
                    Object.assign(u, {
                        can_ggk: y
                    });
                    g.hasShowPage("ScrapingCardPage") ? s.trigger(c.BEGIN_SCRAP_CARD, u) : g.showPage("ScrapingCardPage", u);
                    y ? l.reportVideoBuriedPoint(VideoBuriedPoint.SCRAP_CARD_1) : l.reportVideoBuriedPoint(VideoBuriedPoint.SCRAP_CARD_2);
                } else if (e == TravelEvent.SKILL) l.reportVideoBuriedPoint(VideoBuriedPoint.GIVE_SKILL); else if (e == TravelEvent.HOTAIRBALLON) {
                    l.reportVideoBuriedPoint(VideoBuriedPoint.HOT_AIR_BALLON);
                    l.setHotAirBallonFlag(_);
                    s.trigger(c.BLLON_SHOW_STATE);
                    g.showPage("ToastPage", {
                        type: 1,
                        count: m,
                        is_travel: false,
                        page_type: 1
                    });
                }
            } else n.message && f.showManageViewToast(n.message);
        }), u.create(this, function () {
            f.showManageViewToast("网络异常,请检查网络");
        }));
    };
    public reportOutsideGuideStep(e, t?) {
        h.reportOutsideGuideStep({
            step: e
        }, u.create(this, function (a) {
            p.log("上报关卡外新手引导步骤", e);
            n.isOptimizeTravelFundFlag() ? d.reportData("outside_guide_experiment_step", {
                step: e
            }) : d.reportData("outside_guide_step", {
                step: e
            });
            if (a && 1 == a.code) {
                var o = a.data, i = o.gold_balance;
                o.reward;
                t && t();
                if (5 == e) {
                    r.gold_balance = i;
                    s.trigger(c.UPDATE_FUND);
                }
            } else a.message && f.showManageViewToast(a.message);
        }), u.create(this, function () {
            f.showManageViewToast("网络异常,请检查网络");
        }));
    };
}

export default PeripheralSystemMgr._getInstance();
